package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.ApFollowBehaviorService;
import com.heima.common.constants.message.FollowBehaviorConstants;
import com.heima.model.behavior.dtos.FollowBehaviorDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FollowBehaviorListener {
    @Autowired
    ApFollowBehaviorService apFollowBehaviorService;

    @KafkaListener(topics = FollowBehaviorConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void receiverMessage(String msg){
        //接收到消息
        log.info("接收到添加关注行为====>请求参数 {}",msg);
        //调用方法执行
        FollowBehaviorDto followBehaviorDto = JSON.parseObject(msg, FollowBehaviorDto.class);
        apFollowBehaviorService.saveFollowBehavior(followBehaviorDto);
        log.info("添加关注行为结束");
    }
}
